package com.example.juccode.juc01threadpool.demo01;

import javafx.concurrent.Task;

import java.util.concurrent.*;

/**
 * @author: zhongkui 1365693530@qq.com
 * @Date: 2025/10/22
 */
public class Main {
    public static void main(String[] args) {
        // 创建线程池
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(30, 40, 10L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(),
                new CustomThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy());
        // 提交任务
        for (int i = 0; i < 50; i++) {
            TaskDemo taskDemo = new TaskDemo();
            threadPool.execute(taskDemo);
        }
        // 关闭线程池
        threadPool.shutdown();
    }

}

class TaskDemo implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
